/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package psremovedigitsfromcategory;

import com.gpaltan.db.DBManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author srkrishnan
 */
public class Psremovedigitsfromcategory {

    String url = "jdbc:mysql://tiptoptop.com:3306/";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "joyhandb_hyrtedu";
    String password = "P09gR7nU1t2x";
    String dbname = "joyhandb_tipdanye";

    public Psremovedigitsfromcategory() {
        try {
            DBManager dbmanager = new DBManager(url, dbname, driver, userName, password);

            dbmanager.connectDB();
            Connection conn = dbmanager.getConnection();
            // our SQL SELECT query. 
            // if you only need a few columns, specify them by name instead of using "*"
            String query = "select name,id_lang,id_category from ps_category_lang";

            // create the java statement
            Statement st = conn.createStatement();

            // execute the query, and get a java resultset
            ResultSet rs = st.executeQuery(query);
            
            while(rs.next())
            {
                String name =rs.getString("name");
                int id_lang=rs.getInt("id_lang");
                int id_category=rs.getInt("id_category");
                String newname = name.substring(name.indexOf(".")+1);
                System.out.println(id_lang + " "+id_category + " "+name+"=>"+newname);
                
                 query = "update ps_category_lang "
                            + "set name=? "
                            + "where name=? and id_lang=? and id_category=?";

                    PreparedStatement psmt = conn.prepareStatement(query);
                    psmt.setString(1, newname);
                    psmt.setString(2, name);
                    psmt.setInt(3, id_lang);
                    psmt.setInt(4, id_category);
                    


                    ////System.out.println(psmt);

                    psmt.executeUpdate();
                
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(Psremovedigitsfromcategory.class.getName()).log(Level.SEVERE, null, ex);
        }

        

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Psremovedigitsfromcategory();
    }
}
